/*
 * SplashScreen.java - Splash screen
 * Copyright (C) 1998, 1999, 2000 Slava Pestov
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package com.gemalto.Kryptik.Gui;

import javax.swing.border.*;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.util.Random;
import com.gemalto.Kryptik.*;
import com.gemalto.Kryptik.Util.*;

public class SplashScreen extends JWindow
{
	public SplashScreen()
	{
		setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
		setSize(354,134);

//		JPanel splash = new JPanel(); //new BorderLayout(12,12));
		Container splash = getContentPane();
		splash.setLayout(null);
//		splash.setBorder(new CompoundBorder(
//			new MatteBorder(1,1,1,1,Color.black),
//			new EmptyBorder(12,12,12,12)));
//		splash.setBackground(Color.white);

		Dimension screen = getToolkit().getScreenSize();
		//pack();
		setLocation((screen.width - getSize().width) / 2,
			(screen.height - getSize().height) / 2);
        	Insets inset = splash.getInsets();
        

		ImageIcon icon = Util.getIcon("logo.gif");
		if(icon != null)
		{
			JLabel label = new JLabel(icon);
			//label.setBorder(new MatteBorder(1,1,1,1,Color.black));
			splash.add(label);
			label.setBounds(0+inset.left,0+inset.top,354,134);
		}
		//JLabel label = new JLabel("Kryptik "+Main.getVersion());
		//splash.add(BorderLayout.NORTH,label);
		//

                // PS 9/1/2007  - match progress bar colors with logo
                UIManager.put("ProgressBar.selectionBackground",new Color(107,89,74) );
                UIManager.put("ProgressBar.selectionForeground",Color.WHITE);

                UIManager.put("ProgressBar.foreground", new Color(107,89,74));
                //UIManager.put("ProgressBar.foreground", new Color(255,130,24));
                UIManager.put("ProgressBar.background", Color.WHITE);
                //UIManager.put("ProgressBar.background", new Color(107,89,74));

		progress = new JProgressBar(0,4);
		progress.setStringPainted(true);
		progress.setBorderPainted(false);
		progress.setString("Kryptik version: " + Main.getVersion());
		//progress.setBackground(Color.white);
		splash.add(progress);
		progress.setBounds(10+inset.left,10+inset.top,334,20);

//		setContentPane(splash);


		setVisible(true);
	}

	public void advance()
	{
		try
		{
			SwingUtilities.invokeAndWait(new Runnable() {
				public void run()
				{
					progress.setValue(progress.getValue() + 1);
				}
			});
			Thread.yield();
		}
		catch(Exception e)
		{
		}
	}

	public void advance(String s)
	{
		try
		{
			progress.setString(s);
			SwingUtilities.invokeAndWait(new Runnable() {
				public void run()
				{
					progress.setValue(progress.getValue() + 1);
				}
			});
			Thread.yield();
		}
		catch(Exception e)
		{
		}
	}

	// private members
	private JProgressBar progress;
}
